package org.example.SlApi.JbxxApi;

import io.restassured.RestAssured;
import io.restassured.response.Response;
import org.apache.commons.codec.net.URLCodec;
import org.example.JycInfo;
import org.example.utils.ReadConf;
import org.example.utils.TestDataLoader;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static org.example.RestClient.givenWithCookies;
import static org.example.RestClient.loginAndUpdateCookies;
import static org.example.SlApi.JbxxApi.QyjbxxbcApi.initJyclist;

public class Zsbc {
    public static void main(String[] args) throws IOException {
        zsbc();
    }
    private  static TestDataLoader testDataLoader;

    public static int zsbc() throws IOException {
        // 登录并更新cookies
//        proloc_location: 的回复老大是
//        province: 浙江省
//        city: 宁波市
//        district: 江北区
//        street: 原中马路杭州市上城区清波街道高端护肤的

        if (testDataLoader == null) {
            testDataLoader = new TestDataLoader();
        }
        loginAndUpdateCookies();
        RestAssured.baseURI = ReadConf.getHost(); // 设置基础URI
        List<JycInfo> jycInfoList = new ArrayList<>();
        Map<String, String> testData = testDataLoader.getTestData();

        String nameZh = testData.get("nameZh");


        String proloc_location = nameZh;
        String province = "浙江省";
        String city = "杭州市";
        String district = "上城区";
        String street = "清波街道";
        URLCodec urlCodec = new URLCodec();
        String encodedParam1 = URLEncoder.encode(proloc_location, "UTF-8");
        String encodedParam2 = URLEncoder.encode(province, "UTF-8");
        String encodedParam3 = URLEncoder.encode(city, "UTF-8");
        String encodedParam4 = URLEncoder.encode(district, "UTF-8");
        String encodedParam5 = URLEncoder.encode(street, "UTF-8");


            String data = "&proloc_location="+encodedParam1+"&province="+encodedParam2+"&city="+encodedParam3+"&district="+encodedParam4+"&street=" + encodedParam5;

            Response response = givenWithCookies()
                 .header("Referer","http://10.1.10.141:9031/ywtSldj.do?method=editZssblr&sbid=2024091126832376&name_id=202409111214517205223&pripid=&ljmsign=2&csrftoken=")
                    .body(data)
//                .cookies(cookies)
//                .params(formParams)
                    .log().all()
                    .post("ywtSldj.do?method=checkZmqDom&csrftoken="); // 注意：可能需要有效的 CSRF Token

            int statusCode = Integer.parseInt(String.valueOf(response.getStatusCode()));
            Map<String, String> cookies = response.getCookies();
            System.out.println(cookies);

            System.out.println(statusCode);
            String body = response.getBody().asString();
            System.out.println(body);


            return statusCode;
        }
    }

